1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| #include <iostream> #include <cstdio> #include <cstring>
#define lson root << 1 #define rson root << 1 | 1
using namespace std;
const int MAXN = 5e04 + 10;
int N, M; int a[MAXN]= {0};
struct baseSt { int b[32]; int subsum;
void init () { memset (b, 0, sizeof (b)); } void append (int x) { for (int j = 31; j >= 1; j --) if (x & (1 << (j - 1))) { if (! b[j]) { b[j] = x; break; } else x ^= b[j]; } } } ; baseSt base[MAXN << 2]; baseSt merge (baseSt A, baseSt B) { baseSt ret; ret.init (); for (int j = 31; j >= 1; j --) { if (A.b[j]) ret.b[j] = A.b[j]; else ret.b[j] = B.b[j]; } for (int j = 31; j >= 1; j --) if (A.b[j] && B.b[j]) ret.append (B.b[j]); ret.subsum = A.subsum ^ B.subsum; return ret; } void build (int root, int left, int right) { base[root].init (); if (left == right) { base[root].subsum = a[left]; base[root].append (base[root].subsum); return ; } int mid = (left + right) >> 1; build (lson, left, mid); build (rson, mid + 1, right); base[root] = merge (base[lson], base[rson]); } void modify (int root, int left, int right, int posi, int delta) { if (left == right) { base[root].init (); base[root].subsum ^= delta, base[root].append (base[root].subsum); return ; } int mid = (left + right) >> 1; if (posi <= mid) modify (lson, left, mid, posi, delta); else modify (rson, mid + 1, right, posi, delta); base[root] = merge (base[lson], base[rson]); } baseSt query_base (int root, int left, int right, int L, int R) { if (L <= left && right <= R) return base[root]; int mid = (left + right) >> 1; baseSt ret; ret.init (); if (L <= mid) ret = merge (ret, query_base (lson, left, mid, L, R)); if (R > mid) ret = merge (ret, query_base (rson, mid + 1, right, L, R)); return ret; } int query_value (int root, int left, int right, int posi) { if (left == right) return base[root].subsum; int mid = (left + right) >> 1; if (posi <= mid) return query_value (lson, left, mid, posi); else return query_value (rson, mid + 1, right, posi) ^ base[lson].subsum; }
inline int solve (int x, baseSt A) { int ret = x; for (int j = 31; j >= 1; j --) ret = max (ret, ret ^ A.b[j]); return ret; }
int getnum () { int num = 0; char ch = getchar ();
while (! isdigit (ch)) ch = getchar (); while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar ();
return num; }
int main () { N = getnum (), M = getnum (); for (int i = 1; i <= N; i ++) a[i] = getnum (); for (int i = N - 1; i >= 1; i --) a[i + 1] ^= a[i]; build (1, 1, N); for (int i = 1; i <= M; i ++) { int opt = getnum (), l = getnum (), r = getnum (), x = getnum (); if (opt == 1) { modify (1, 1, N, l, x); if (r < N) modify (1, 1, N, r + 1, x); } else { int delta = query_value (1, 1, N, l); if (l == r) printf ("%d\n", max (x ^ delta, x)); else { baseSt bas = query_base (1, 1, N, l + 1, r); bas.append (delta); printf ("%d\n", solve (x, bas)); } } }
return 0; }
|